using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace AjGenesisStudio.Commands
{
    class NewFileFromTemplateCommand : Command
    {

        private string templatePath;
        public string TemplatePath
        {
            get { return templatePath; }
            set { templatePath = value; }
        }
	
        public override bool Execute()
        {
            if (!File.Exists(templatePath))
                return false;

            OpenNew();

            return true;
        }

        private void OpenNew()
        {
            Global.Instance.StartWork();
            
            string ext = Path.GetExtension(templatePath);
            Documents.Document doc = null;

            switch (ext)
            {
                case ".tpl":
                    doc = new Documents.TemplateDocument();
                    break;
                //case ".":
                //    //doc = new Documents.;
                //    break;
                default:
                    doc = new Documents.Document();
                    break;
            }

            doc.DefaultExtension = ext;
            doc.editor.Open(templatePath);
            doc.editor.Saved = false;
            doc.Open();
            Global.Instance.MainForm.ShowDocument(doc);

            Global.Instance.EndWork();
        }

    }
}
